package com.atguigu.a_collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;

public class Demo {
    public static void main(String[] args) {
        //利用多态性创建"接口对象"
        Collection<Integer> collection1 = new ArrayList<>();
        Collection<String> collection2 = new HashSet<>();

        System.out.println("collection1 = " + collection1);//[] -> 展示集合中的元素
        System.out.println("collection2 = " + collection2);//[] -> 展示集合中的元素

        //添加元素
        collection1.add(100);//Integer e = 100;
        collection2.add("Hello");//String e = "Hello";

        System.out.println("collection1 = " + collection1);//[] -> 展示集合中的元素
        System.out.println("collection2 = " + collection2);//[] -> 展示集合中的元素
        System.out.println("--------------------------------------");
        //删除元素
        System.out.println("collection1.remove(200) = " + collection1.remove(200));//false
        System.out.println("collection1 = " + collection1);

        System.out.println("collection2.remove(\"Hello\") = " + collection2.remove("Hello"));//true
        System.out.println("collection2 = " + collection2);
        System.out.println("--------------------------------------");
        System.out.println("collection1.contains(100) = " + collection1.contains(100));
        System.out.println("collection1.contains(200) = " + collection1.contains(200));
        System.out.println("--------------------------------------");
        System.out.println("collection1.isEmpty() = " + collection1.isEmpty());//false
        System.out.println("collection2.isEmpty() = " + collection2.isEmpty());//true
        System.out.println("--------------------------------------");
        System.out.println("collection1.size() = " + collection1.size());//1
        System.out.println("collection2.size() = " + collection2.size());//0
    }
}
